package com.enbatis.mybatisplugs.controller;

import com.enbatis.mybatisplugs.base.BaseController;
import com.enbatis.mybatisplugs.commons.sql.Wrapper;
import com.enbatis.mybatisplugs.commons.utils.ResultReturn;
import com.enbatis.mybatisplugs.entity.SysMsg;
import com.enbatis.mybatisplugs.entity.TCategory;
import com.enbatis.mybatisplugs.entity.vo.SysMsgRelUserVO;
import com.enbatis.mybatisplugs.plugin.Pages;
import com.github.pagehelper.Page;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.enbatis.mybatisplugs.entity.SysMsgRelUser;
import com.enbatis.mybatisplugs.service.SysMsgRelUserService;


import java.util.List;

@RestController
@RequestMapping("v1/sys_msg_rel_user")
public class SysMsgRelUserController extends BaseController {

@Autowired
private SysMsgRelUserService sysMsgRelUserService;


    @PostMapping("/add")
    public ResultReturn<SysMsgRelUser> add(@RequestBody SysMsgRelUser sysMsgRelUser){
        return  success(sysMsgRelUserService.insert(sysMsgRelUser));
    }


    @DeleteMapping("/delete")
    public ResultReturn<Integer> delete(@RequestParam("id") Long id){
        return success(sysMsgRelUserService.deleteById(id));
    }


    @PutMapping("/{id}")
    public  ResultReturn<Integer> update(@PathVariable("id") Long id,@RequestBody SysMsgRelUser sysMsgRelUser){
        sysMsgRelUser.setId(id);
        return success(sysMsgRelUserService.updateById(sysMsgRelUser));
    }

    @PutMapping("/read/{id}")
    public  ResultReturn<Integer> updateRead(@PathVariable("id") Long id,@RequestBody SysMsgRelUser sysMsgRelUser){
        sysMsgRelUser.setId(id);
        return success(sysMsgRelUserService.updateReadById(sysMsgRelUser));
    }


    @GetMapping("/{id}")
    public ResultReturn<SysMsgRelUser> get(@PathVariable("id") Long id) {
        return success(sysMsgRelUserService.getById(id));
    }


    @GetMapping("/list")
    public ResultReturn<List<SysMsgRelUser>> getList(SysMsgRelUser sysMsgRelUser){
        return success(sysMsgRelUserService.list(new Wrapper<>(sysMsgRelUser)));
    }


    @GetMapping("/get_msg_count")
    public ResultReturn getMsgCount( ){
        return success(sysMsgRelUserService.getMsgCount(getAccount()));
    }




    @ApiOperation(value = "分页列表", notes = "分页查询数据列表")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "page", value = "请求数据的页码", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "rows", value = "每页条数", required = true, paramType = "query", dataType = "int"),
            @ApiImplicitParam(name = "sidx", value = "排序字段", paramType = "query", dataType = "String"),
            @ApiImplicitParam(name = "sord", value = "排序方式", paramType = "query", dataType = "String"),
    })
    @PostMapping("/page_vc")
    public ResultReturn<Pages<SysMsgRelUserVO>> getPage(@RequestBody SysMsgRelUserVO msgRelUserVO){
        Page<SysMsgRelUserVO> page= getPage();
        msgRelUserVO.setUserId(getAccount().getId());
        return success(sysMsgRelUserService.pageVO(page,msgRelUserVO));
    }

}
